/**
 * Created by wangfan on 2017/4/21.
 */


var editor; // use a global for the submit and return data rendering
$(document).ready(function () {

    var id =getUrlParam("id");
    var isdelete =getUrlParam("delete");
    var backid =getUrlParam("backid");
    if(isdelete==1){

        $.ajax({
            url: '/commis/api/backNotify/remove?id='+backid,
            async: false,
            dataType: 'json',
            success: function (response) {
                if(response.status==0){
                    console.log("delete success");
                    $.ajax({
                        url: '/commis/api/index/notify',
                        type: "GET",
                        async: false,
                        dataType: 'json',
                        success: function (result) {
                            if (result.status == 0) {
                                countNotify(result);
                            }else{
                                alert(result.msg);
                            }


                        }, error: function (msg) {
                            alert("发生错误");
                        }
                    })
                }else {
                    console.log("delete failed");
                }


            }, error: function () {
                console.log("error");
            }
        });


    }


    $.ajax({
        url: '/commis/api/officeSupplies/'+id,
        async: false,
        dataType: 'json',
        success: function (response) {
            if(response.isOff==7||response.isOff==1){
                $("#audit").show();
            }
            $("#subNO").text(response.submitNumber);

            $("#detail").append(' <tr><td class="col-md-1">社区名称</td> <td colspan="4"><span>'+response.community.communityName+'</span></td></tr>');
            $("#detail").append(' <tr><td class="col-md-1">申请时间</td> <td colspan="4"><span>'+response.registerTime+'</span></td></tr>');
            $("#detail").append(' <tr><td class="col-md-1">购置类型</td> <td colspan="4"><span>'+response.workexpType+'</span></td></tr>');

            var detail =response.hasDetail;
            if(0===detail){
                $("#detail").append(' <tr><td class="col-md-1">明细及金额<br>（若购办公用品，请列清购物明细）</td> <td colspan="4"><span>共计 '+response.sum+' 元</span></td></tr>');

            }else if(1===detail){
                var length =response.details.length;
                var rows = parseInt(length)+parseInt(1);
                alert(length)
                $("#detail").append('<tr> <td rowspan="'+rows+'" class="col-md-1">明细及金额（若购办公用品，请列清购物明细）</td><td class="col-md-1">物品名称</td> <td class="col-md-1">单价</td> <td class="col-md-1">数量</td> <td class="col-md-1">金额</td></tr>');


                for(var i=0;i<length;i++){
                    var item = response.details[i];
                    $("#detail").append('<tr><td><span>'+item.suppliesName+'</span></td><td ><span>'+item.unitCost+'</span></td> <td ><span >'+item.count+'</span></td> <td ><span>'+item.cost+'</span></td></tr>');


                }


            }
            $("#detail").append(' <tr><td class="col-md-1">总计</td> <td colspan="4"><span>共 '+response.sum+' 元</span></td></tr>');
            $("#detail").append(' <tr><td class="col-md-1">预计消费方式</td> <td colspan="4"><span>'+response.paymentMode+'</span></td></tr>');
            $("#detail").append(' <tr><td class="col-md-1">备注</td> <td colspan="4"><span>'+response.comment+'</span></td></tr>');


          /*  $("#subNO").text(response.submitNumber);
            $("#communityName").text(response.community.communityName);
            $("#registerTime").text(response.registerTime);
            $("#workexpType").text(response.workexpType);
            $("#suppliesName").text(response.suppliesName);
            $("#unitCost").text(response.unitCost);
            $("#count").text(response.count);
            $("#sum").text(response.sum);
            $("#paymentMode").text(response.paymentMode);
            $("#comment").text(response.comment);*/


        }, error: function () {

        }
    });

    $('#changeTable').DataTable({

        ajax: "/commis/api/officeSupplies/changeDatatables?id=" + id,

        autoWidth: true,
        responsive: true,
        serverSide: true,
        processing: true,
        lengthChange: false,//是否允许用户改变表格每页显示的记录数
        ordering: false,//是否允许用户排序
        paging: true,//是否分页
        pagingType: "full_numbers",//除首页、上一页、下一页、末页四个按钮还有页数按钮
        searching: false,//是否开始本地搜索
        stateSave: false,//刷新时是否保存状态
        autoWidth: true,//自动计算宽度
        language: {
            emptyTable: "没有数据",
            search: "搜索:",
            paginate: {
                first: "首页",
                previous: "上一页",
                next: "下一页",
                last: "尾页"

            },
            lengthMenu: "每页 _MENU_ 条记录",
            zeroRecords: "没有找到记录",
            info: "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )，共 _TOTAL_ 项",
            infoEmpty: "无记录",
            infoFiltered: "(从 _MAX_ 条记录过滤)"
        },
        columns: [
            {
                data: 'current_state',
                render: function (data, type, row) {
                    if (0 == data) {
                        return "待审核";
                    } else if (1 == data) {
                        return "同意"
                    }
                    else if (2 == data) {
                        return "不同意";
                    }
                    else if(3 == data)
                    {
                        return "建议";
                    }else if(4 == data)
                    {
                        return "更新";
                    }else if(5 == data)
                    {
                        return "重新提交";
                    }
                }
            }, {
                data: 'real_name', defaultContent: ""
            }, {
                data: 'current_datetime', defaultContent: ""

            }, {
                data: 'suggest', defaultContent: ""

            },  {
                data: 'submit_number', defaultContent: ""
            }]


    });







})
//设置框架
$(function () {
    $("#page_style").frame({
        float: 'left',
        menu_nav: '.Quick_operation',
        color_btn: '.skin_select',
        Sellerber_menu: '.list_content',
        Sellerber_header: '.Sellerber_header',
    });
});
$("#iframe_box").niceScroll({
    cursorcolor: "#888888",
    cursoropacitymax: 1,
    touchbehavior: false,
    cursorwidth: "5px",
    cursorborder: "0",
    cursorborderradius: "5px"
});
/*********************/
require.config({
    paths: {
        echarts: './js/dist'
    }
});